package 二叉树;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class 将数组转换成二叉树 {
	
	private static List<Integer> list=new ArrayList();
	
	static class TreeNode{
		
		  int val;
		     TreeNode left;
		     TreeNode right;
		     TreeNode(int x) { val = x; }
	}
	
	public static TreeNode createTree(int[] nums,int start) {
		
		if(start >nums.length) {
			return null;
		}
		TreeNode root = new TreeNode(nums[start]);
		int left =2*start+1;
		int right =2*start+2;
		if(left<nums.length-1) {
			root.left=createTree(nums,left);
		}else {
			root.left=null;
		}
		
		if(right<=nums.length-1) {
			root.right=createTree(nums,right);
		}else {
			root.right=null;
		}
		return root;			
	}
	
	public static void order(TreeNode root) {
		
		if(root==null) return;
		if(root.left!=null) {
			order(root.left);
		}
		System.out.println(root.val);
		list.add(root.val);
		if(root.right!=null) {
			order(root.right);
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String nextLine = sc.nextLine();
		String[] strings = nextLine.split(",");
		int[] nums = new int[strings.length];
		for (int i = 0; i < strings.length; i++) {
			nums[i]=Integer.valueOf(strings[i]);
		}
		TreeNode root = createTree(nums,0);
		if(root ==null) System.out.println("None");
		order(root);
		for (int i = 1; i < list.size(); i++) {
			//System.out.println(list.get(i));
			/*if(list.get(i)<=list.get(i-1)) {
				System.out.println("False");
				break;
			}*/
		}
		
	}
}
